<%--管理员-博客管理列表--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>图形图像处理交流网站</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <%--搜索相关--%>
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                    <div class="layui-form-item layui-form layui-form-pane demoTable">

                        <div class="layui-inline">
                            <label class="layui-form-label">标题/作者</label>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="id" placeholder="用户名/昵称/邮箱/注册类型" id="demoReload" onfocus="this.placeholder=''" onblur="this.placeholder='用户名/昵称/邮箱/注册类型'" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-primary"  data-type="reload" id="search" lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
            </div>
        </fieldset>

        <%--表格相关--%>
        <table class="layui-hide" id="test" lay-filter="test"></table>
            <%--左上角工具栏--%>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="getCheckData"><i class="layui-icon">&#xe640;</i>批量删除</button>
                </div>
            </script>
            <%--表格操作--%>
            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>

    </div>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.js" ></script>
<script src="${pageContext.request.contextPath}/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>

<%--表格渲染--%>
<script>
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#test'
            ,url:'${pageContext.request.contextPath}/admin/user/admin_list.do'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            , id: 'test'
            ,title: '用户数据表'
            ,cols: [[
                 {fixed: 'left',type: 'checkbox',width:'6%'}
                ,{field:'uId', title:'ID',type:"numbers", width:'10%', unresize: true, align:'center'}
                ,{field:'userName', title:'用户名', width:'12%', sort: true, align:'center'}
                ,{field:'uNickName', title:'用户昵称', width:'12%', sort: true, align:'center'}
                ,{field:'uType', title:'注册类型', width:'12%', sort: true, align:'center'}
                ,{field:'uEmail', title:'邮箱', width:'18%', sort: true, align:'center'}
                ,{field:'uCreateTime', title:'注册时间', width:'16%',sort: true, align:'center'}
                ,{title:'操作', toolbar: '#barDemo', width:'14%', align:'center'}
            ]]
            ,page: true,
            text: {
                none: '暂无相关数据'
            }
        });
        //数据表格重载
        // 执行搜索，表格重载
        var $ = layui.$,active={
            reload:function(){
                var demoReload = $('#demoReload').val();
                table.reload('test', {
                    method: 'get'
                    , where: {
                        'keywords': demoReload
                        ,'time':new Date().valueOf()
                    }
                    , page: {
                        curr: 1
                    }
                });
            }
        }

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    if(data.length!=0){
                        var ids = [];//用户id
                        var uName=[];//用户名
                        for (var i = 0; i < data.length; i++) { //循环筛选出id
                            ids.push(data[i].uId);
                            uName.push(data[i].userName);
                        }
                        //发送删除请求
                        layer.confirm("确认要删除"+JSON.stringify(uName)+"吗，删除后不能恢复", { title: "删除确认" }, function(index){
                            senddel(ids);
                            return false;
                        });
                    }else{
                        layer.msg("您还未选择用户！",{icon: 5});
                    }

                    // layer.alert(JSON.stringify(uName));
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    var ids =data.uId;
                    senddel(ids);
                    return false;
                });
            }else if(obj.event === 'detail'){//查看
                window.open("${pageContext.request.contextPath}/blog/to_home.do?uId="+data.uId);
            }
        });

        function senddel(ids){
            $.ajax({
                url: "${pageContext.request.contextPath}/admin/user/admin_delete.do",
                type: "post",
                dataType:'json',
                data: 'ids='+ids,
                success: function (result) {
                    if (result.msg == 200) {
                        layer.msg('删除成功');
                        table.reload('test',{});
                    }else{
                        layer.msg(result.msg);
                    }
                }
            });
        };

    });


</script>


</body>
</html>
